package com.eduService.teacher.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eduService.teacher.entity.CrmBanner;
import com.eduService.teacher.entity.EduTeacher;
import com.eduService.teacher.service.ICrmBannerService;
import com.eduService.teacher.utils.R;
import lombok.Getter;
import lombok.extern.flogger.Flogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author Mr.tang
 * @since 2022-05-14
 */
@CrossOrigin
@RestController
@RequestMapping("/admincrmbanner")
public class CrmBannerController {

    @Autowired
    private ICrmBannerService crmBannerService;
    /*
    *  分页查询banner
    * */
    @PostMapping("getallbannerpage/{page}/{limit}")
    public R getAllBannerPage(@PathVariable("page") Long page ,@PathVariable("limit")Long limit){
        Page<CrmBanner> tpage = new Page<>(page,limit);
        crmBannerService.page(tpage,null);
        List<CrmBanner> records = tpage.getRecords();
        long total = tpage.getTotal();
        return R.ok().data("total",total).data("data",records);
    }

    /*
    * 根据指定Id删除bannner
    * */
    @DeleteMapping("delbanner/{id}")
    public R delBannerById(@PathVariable("id")String id){
        boolean b = crmBannerService.removeById(id);
        if (b){
            return R.ok().msg("删除成功！");
        }else
        {
            return R.error().msg("删除失败！");
        }
    }

    /*
    * 添加Banner
    * */
    @PostMapping("savebanner")
    public R saveBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok().msg("添加成功！");
    }

    /*
    *更改banner信息
     */
    @PutMapping("updatebanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok().msg("修改成功！");
    }

    /*
    * 根据ID查询banner
    * */
    @GetMapping("getABanner/{id}")
    public R getABannerById(@PathVariable("id") String id){
        return R.ok().data("banner",crmBannerService.getById(id));
    }


}
